<?php
namespace Apps\Front\Controllers;
use Apps\Front\Controllers\ControllerBase;
use Phalcon\Filter as Filter;
use Apps\Model\User;

class RegisterController extends ControllerBase{

    public function registerokAction(){
      $this->view->disable();
      $tel=$this->request->getPost("tel","int");
      $pwd=$this->request->getPost("pwd","string");
      $repwd=$this->request->getPost("repwd","string");
      //过滤空格
      $filter = new Filter();
      $tel = $filter->sanitize($tel, "trim");
      $pwd = $filter->sanitize($pwd, "trim");
      $repwd = $filter->sanitize($repwd, "trim");
      if(strlen($tel)<11){
      	$this->jump('Index/index','号码长度不能小于11位');
      	return;
      }
      if(empty($tel)|| empty($pwd)){
      	$this->jump('Index/index','号码和密码不能为空');
      	return;
      }
      if($pwd!=$repwd){
      	$this->jump('Index/index','密码两次输入不一致');
      	return;
      }
      $user=User::findFirst("tel=".$tel);
      if($user){
      	$this->jump('Index/index','手机号码已被注册');
      	return;
      }
      $map=new User();
      $map -> tel = $tel;
      $map -> pwd = $pwd;
      $map -> save();
      $this->session->set('operator',$map);
      $this->jump('Index/index','注册成功正在登陆');
    }

}
?>